package cn.com.dashihui.api.radisysnc.inter.impl;


import com.jfinal.plugin.redis.Cache;
import com.jfinal.plugin.redis.Redis;

import cn.com.dashihui.api.dao.Goods;
import cn.com.dashihui.api.dao.OrderG;
import cn.com.dashihui.api.radisysnc.inter.IGoodsBiz;

/**
 * ***********************************************
 * <p>
 * 类名: goodsSaleBizImpl
 * </p>
 * <p>
 * 描述: 在redis里处理数据
 * </p>
 * @author niufc @date 2019年8月20日
 * ************************************************
 */
public class ImplGoodsBiz implements IGoodsBiz {
	// 获取默认的Redis Cache对象
	// 最先创建的Cache将成为主Cache，所以可以省去cacheName参数来获取
	// Cache newsCache = Redis.use("cacheName");
	private Cache newsCache = Redis.use();

	@Override
	public void updateGoods(Goods goods) {
		goods.update();
	}

	@Override
	public Goods loadGoodsByGoodsId(Integer id) {
		return Goods.me().findById(id);
	}

	@Override
	public void setGoodsCache(Goods goods) {
		newsCache.set("goods:" + goods.getInt("id"), goods);
	}

	@Override
	public void removeGoodsCache(Integer id) {
		newsCache.del("goods:" + id);
	}

	@Override
	public Goods loadGoodsCache(Integer id) {
		return newsCache.get("goods:" + id);
	}

	@Override
	public void updateOrderG(OrderG order) {
		 order.update();
	}

	@Override
	public OrderG loadOrderG(String orderNum) {
		return OrderG.me().findFirst("SELECT * FROM t_bus_order_gb WHERE orderNum = ?", orderNum);
	}

	@Override
	public void setOrderGCache(OrderG order) {
		newsCache.set("orderG:" + order.getStr("orderNum"), order);
	}

	@Override
	public void removeOrderGCache(String orderNum) {
		newsCache.del("orderG:" + orderNum);
	}

	@Override
	public OrderG loadOrderGCache(String orderNum) {
		return newsCache.get("orderG:" + orderNum);
	}

	

}
